//
//  ZYIdentityController.m
//  生活小助手
//
//  Created by 振亚 姜 on 14-8-9.
//  Copyright (c) 2014年 lxz. All rights reserved.
//

#import "ZYIdentityController.h"
#import "ZYInfoSearchController.h"
#import "ZYRevealSearchController.h"
#import "ZYLoseSearchController.h"

@interface ZYIdentityController ()

@property (strong, nonatomic) ZYInfoSearchController *infoSearchController;
@property (strong, nonatomic) ZYRevealSearchController *revealSearchController;
@property (strong, nonatomic) ZYLoseSearchController *loseSearchController;
//@property (strong, nonatomic) NSMutableDictionary *controllerDict;
@property (strong, nonatomic) UIViewController *selectedController;

@end

@implementation ZYIdentityController

- (NSMutableDictionary *)controllerDict
{
    if (!_controllerDict) {
        _controllerDict = [NSMutableDictionary dictionary];
    }
    return _controllerDict;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = @"身份证查询";
    
    self.view.backgroundColor = kGlobalBackgroundColor;
    
    [self addViews];
    
}

- (void)addViews
{
    UISegmentedControl *segementControl = [[UISegmentedControl alloc] initWithItems:@[@"信息查询", @"泄露查询", @"挂失查询"]];
    segementControl.y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
    segementControl.width = self.view.width;
    [segementControl addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];
    self.segementControl = segementControl;
    [self.view addSubview:segementControl];
    
    segementControl.selectedSegmentIndex = 0;
    
    self.infoSearchController = [[ZYInfoSearchController alloc] init];
    self.revealSearchController = [[ZYRevealSearchController alloc] init];
    self.loseSearchController = [[ZYLoseSearchController alloc] init];
    [self addChildViewController:self.infoSearchController];
    [self addChildViewController:self.revealSearchController];
    [self addChildViewController:self.loseSearchController];
    
    [self.view addSubview:self.infoSearchController.view];
    self.selectedController = self.infoSearchController;
    
    self.controllerDict[@(ZYIdentitySearchSubControllerTypeInfo)] = self.infoSearchController;
    self.controllerDict[@(ZYIdentitySearchSubControllerTypeReveal)] = self.revealSearchController;
    self.controllerDict[@(ZYIdentitySearchSubControllerTypeLose)] = self.loseSearchController;
}

- (void)changeValue:(UISegmentedControl *)segementControl
{
    // 设置新选中的controller
    UIViewController *controller = self.controllerDict[@(segementControl.selectedSegmentIndex)];
    // 将新选中的Controller中的View添加到当前View
    [self.view addSubview:controller.view];
    // 移除旧View
    [self.selectedController.view removeFromSuperview];
    // 重置选中的Controller
    self.selectedController = controller;
}



@end
